package com.character.controller;

import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.character.entity.Question;
import com.character.entity.Tester;
import com.character.entity.User;
import com.character.service.MenuService;
import com.character.service.QuestionService;
import com.character.service.TesterService;
import com.character.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * @author:高杰领
 * @date:2021/11/25 14:56
 * @description:页面跳转控制类
 * @version:1.0
 **/
@Controller
public class ForwordController {
    @Resource
    QuestionService questionService;
    @Resource
    TesterService testerService;
    @Resource
    UserService userService;
    @Resource
    MenuService menuService;
    /**
     *
     * @param
     * @return java.lang.String
     * @author 高冷
     * @description:请求此地址访问question.html页面
     * @date 2021/11/25 15:13
     */
    @RequestMapping("/showQuestion")
    public String showQuestion(){
        return "question";
    }
    /**
     *
     * @param
     * @return java.lang.String
     * @author 高冷
     * @description:请求此地址访问tester.html页面
     * @date 2021/11/25 15:13
     */
    @RequestMapping("/showTester")
    public String showTester(){
        return "tester";
    }
    /**
     *
     * @param
     * @return java.lang.String
     * @author 高冷
     * @description:请求此地址访问result.html页面
     * @date 2021/11/26 16:36
     */
    @RequestMapping("/showResult")
    public String showResult(){
        return "result";
    }
    /**
     *
     * @param
     * @return java.lang.String
     * @author 张燕豪
     * @description:resultOne.html页面
     * @date 2021/11/26 16:36
     */
    @RequestMapping("/toResultOne")
    public String resultOne(){
        return "resultOne";
    }

    @RequestMapping("/toText")
    public String text(){
        return "text";
    }
    /**
     *
     * @param
     * @return java.lang.String
     * @author 张燕豪
     * @description:resultAll.html页面
     * @date 2021/11/26 16:36
     */
    @RequestMapping("/toResultAll")
    public String resultAll(){
        return "resultAll";
    }

    /**
     *
     * @param
     * @return java.lang.String
     * @author 高冷
     * @description:请求此地址访问管理员登录界面
     * @date 2021/11/26 16:37
     */
    @RequestMapping("/showAdminLogin")
    public String showAdminLogin(){
        return "index";
    }
    /**
     *
     * @param
     * @return java.lang.String
     * @author 高冷
     * @description:请求此地址访问测试用户登录界面
     * @date 2021/11/26 16:38
     */
    @RequestMapping("/showTesterLogin")
    public String showTesterLogin(){
        return "testerLogin";
    }
    /**
     *
     * @param
     * @return java.lang.String
     * @author 高冷
     * @description:请求此地址访问测试题页面
     * @date 2021/11/26 16:39
     */
    @RequestMapping("/showTestCharacter")
    public ModelAndView showTestCharacter(String phone,ModelAndView modelAndView){
        QueryWrapper<Tester> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone",phone);
        Tester tester = testerService.getOne(queryWrapper);
        QueryWrapper<Question> questionQueryWrapper = new QueryWrapper<>();
        questionQueryWrapper.eq("status",0);
        modelAndView.addObject("tester",tester);
        modelAndView.addObject("questionList",questionService.list(questionQueryWrapper));
        modelAndView.setViewName("testCharacter");
        return modelAndView;
    }
    @RequestMapping("/showDept")
    public String showDept(){
        return "dept";
    }
    /**
     *
     * @param
     * @return java.lang.String
     * @author 高冷
     * @description:显示大布局页面(不用输入任何路径也可以直接访问)
     * @date 2021/12/3 9:19
     */
    @RequestMapping("/showIndex")
    public ModelAndView showIndex(ModelAndView modelAndView,String loginName){
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("login_name",loginName);
        User user = userService.getOne(queryWrapper);
        List<Tree<String>> allMenuByLoginName = menuService.getAllMenuByLoginName(loginName);
        Set<String> allPermsByLoginName = menuService.getAllPermsByLoginName(loginName);
        modelAndView.addObject("user",user);
        modelAndView.addObject("menu",allMenuByLoginName);
        modelAndView.addObject("perms",allPermsByLoginName);
        modelAndView.setViewName("home");
        return modelAndView;
    }
    /**
     *
     * @param
     * @return java.lang.String
     * @author 高冷
     * @description:访问菜单管理页面
     * @date 2021/12/3 9:20
     */
    @RequestMapping("/showMenu")
    public ModelAndView showMenu(ModelAndView modelAndView){
        modelAndView.setViewName("menu");
        return modelAndView;
    }
    @RequestMapping("/showRole")
    public String showRole(){
        return "role";
    }
    @RequestMapping("/showResultOne")
    public ModelAndView showResultOne(ModelAndView modelAndView,String id){
        modelAndView.addObject("id",id);
        modelAndView.setViewName("resultOne");
        return modelAndView;
    }
    @RequestMapping("/showUser")
    public ModelAndView showUser(ModelAndView modelAndView){
        modelAndView.setViewName("user");
        return modelAndView;
    }
    @RequestMapping("/showLog")
    public ModelAndView showLog(ModelAndView modelAndView){
        modelAndView.setViewName("log");
        return modelAndView;
    }
}
